package com.jh.user.repository;

import com.jh.user.pojo.payment.PaymentProfit;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;


/**
 * @author Fuchun
 * @since 1.0
 */
@Repository
public interface PaymentProfitRepository extends JpaRepository<PaymentProfit, Long> {

    @Query(value = "select pp from PaymentProfit pp where pp.status='1'")
    Page<PaymentProfit> queryInitialProfits(Pageable pageable);

    @Query("select pp.posId from PaymentProfit pp where pp.status='0'")
    Page<Long> queryInitialPosIds(Pageable pageable);

    @Modifying
    @Query("update PaymentProfit pp set pp.status='1' where pp.posId in ?1")
    int updateStatusToUnpaid(List<Long> posIds);

    @Query("select p from PaymentProfit p where p.userId = :userId")
    Page<PaymentProfit> queryBalanceDetails(@Param("userId") long userId, Pageable pageable);
}
